/// <summary>
// CodeFx.MySqlProviders - .NET Providers for MySql using the framework CodeFx
// Laurent Morisseau
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Laurent Morisseau
/// </summary>
/// <author><a href="mailto:laurent.morisseau@gmail.com">Laurent Morisseau</a></author>


namespace CodeFx.MySqlProviders
{
    using System;
    using System.Text;
    using System.Web;
    using System.Data;
    using System.ComponentModel;
    using MySql.Data.MySqlClient;
    using System.Collections;
    using CodeFx;
    using CodeFx.Web;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Configuration.Provider;

    [DataObject]
    internal static partial class Aspnet_personalizationallusersDTO
    {

        #region DTO Method

        #region Select
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public static Aspnet_personalizationallusersDAL Select(uint _PathId)
        {
            const string command = "select * from  aspnet_personalizationallusers where PathId =?PathId";


            MySqlConnection conn = ConnectionString.Current.OpenConnection;

            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", _PathId));
            Aspnet_personalizationallusersDAL dataobject = null;
            try
            {
                dataobject = Select(cmd);
            }
            finally
            {
                conn.Close();
            }
            return dataobject;
        }

        #endregion

        #region SelectbyFk
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public static List<Aspnet_personalizationallusersDAL> SelectByFk_PathId(uint PathId)
        {
            const string command = "select * from  aspnet_personalizationallusers where PathId =?PathId";

            MySqlConnection conn = ConnectionString.Current.OpenConnection;

            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", PathId));
            List<Aspnet_personalizationallusersDAL> al = null;
            try
            {
                al = SelectAll(cmd);
            }
            finally
            {
                conn.Close();
            }
            return al;
        }
        #endregion

        #region SelectAll
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public static List<Aspnet_personalizationallusersDAL> SelectAll()
        {
            MySqlConnection conn = ConnectionString.Current.OpenConnection;

            MySqlCommand cmd = new MySqlCommand("select * from aspnet_personalizationallusers", conn);
            List<Aspnet_personalizationallusersDAL> al = null;
            try
            {
                al = SelectAll(cmd);
            }
            finally
            {
                conn.Close();
            }
            return al;
        }
        #endregion

        #region Delete
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public static void Delete(Aspnet_personalizationallusersDAL dataObject)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");

            const string command = "delete from aspnet_personalizationallusers where PathId =?PathId";


            MySqlConnection conn = ConnectionString.Current.OpenConnection;
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", dataObject.PathId));

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new DALException(command, dataObject, ex.InnerException);
            }
            finally
            {
                conn.Close();
            }
        }
        #endregion

        #region ByFkDelete
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, false)]
        public static void DeleteByFk_PathId(Aspnet_personalizationallusersDAL dataObject)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");

            const string command = "delete from aspnet_personalizationallusers where PathId =?PathId";

            MySqlConnection conn = ConnectionString.Current.OpenConnection;
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", dataObject.PathId));


            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new DALException(command, dataObject, ex.InnerException);
            }
            finally
            {
                conn.Close();
            }
        }
        #endregion

        #region Insert
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public static void Insert(Aspnet_personalizationallusersDAL dataObject)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");

            const string command = "insert into aspnet_personalizationallusers (PathId,PageSettings,LastUpdatedDate) values ( ?PathId,?PageSettings,?LastUpdatedDate)";

            MySqlConnection conn = ConnectionString.Current.OpenConnection;

            MySqlCommand cmd = new MySqlCommand(command, conn);

            try
            {
                dataObject.Write(cmd);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new DALException(command, dataObject, ex.InnerException);
            }
            finally
            {
                conn.Close();
            }
        }
        #endregion


        #region Update
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public static void Update(Aspnet_personalizationallusersDAL dataObject)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");
            const string command = "update aspnet_personalizationallusers set PageSettings = ?PageSettings,LastUpdatedDate = ?LastUpdatedDate where PathId = ?PathId";
            MySqlConnection conn = ConnectionString.Current.OpenConnection;
            MySqlCommand cmd = new MySqlCommand(command, conn);
            try
            {
                dataObject.Write(cmd);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new DALException(command, dataObject, ex.InnerException);
            }
            finally
            {
                conn.Close();
            }
        }
        #endregion

        #region Exist
        public static bool Exist(uint _PathId)
        {
            const string command = "select 1 from aspnet_personalizationallusers where PathId =?PathId";

            MySqlConnection conn = ConnectionString.Current.OpenConnection;
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", _PathId));

            try
            {
                return (cmd.ExecuteScalar() != null);
            }
            catch (Exception ex)
            {
                throw new DALException(command, ex.InnerException);
            }
            finally
            {
                conn.Close();
            }
        }

        public static bool Exist(Aspnet_personalizationallusersDAL dataObject)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");

            const string command = "select 1 from aspnet_personalizationallusers where PathId =?PathId and PageSettings =?PageSettings and LastUpdatedDate =?LastUpdatedDate";

            MySqlConnection conn = ConnectionString.Current.OpenConnection;
            MySqlCommand cmd = new MySqlCommand(command, conn);

            cmd.Parameters.Add(new MySqlParameter("?PathId", dataObject.PathId));
            cmd.Parameters.Add(new MySqlParameter("?PageSettings", dataObject.PageSettings));
            cmd.Parameters.Add(new MySqlParameter("?LastUpdatedDate", dataObject.LastUpdatedDate));
            try
            {
                return (cmd.ExecuteScalar() != null);
            }
            catch (Exception ex)
            {
                throw new DALException(command, dataObject, ex.InnerException);
            }
            finally
            {
                conn.Close();
            }

        }
        #endregion

        #endregion

        #region Public methods
        public static Aspnet_personalizationallusersDAL Select(MySqlCommand cmd)
        {
            if (cmd == null)
                throw new ArgumentNullException("cmd");
            Aspnet_personalizationallusersDAL dataObject = null;
            MySqlDataReader dr = null;
            try
            {
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult);
                if (dr.Read())
                {
                    dataObject = new Aspnet_personalizationallusersDAL();
                    dataObject.Read(dr);
                }
            }
            catch (Exception ex)
            {
                throw new DALException(cmd.CommandText, ex.InnerException);
            }
            finally
            {
                if (dr != null)
                    dr.Close();
            }
            return dataObject;
        }

        public static List<Aspnet_personalizationallusersDAL> SelectAll(MySqlCommand cmd)
        {
            if (cmd == null)
                throw new ArgumentNullException("cmd");
            List<Aspnet_personalizationallusersDAL> al = null;
            MySqlDataReader dr = null;
            try
            {
                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    al = new List<Aspnet_personalizationallusersDAL>();
                    while (dr.Read())
                    {
                        Aspnet_personalizationallusersDAL dataObject = new Aspnet_personalizationallusersDAL();
                        dataObject.Read(dr);
                        al.Add(dataObject);
                    }
                    al.TrimExcess();
                }
            }
            catch (Exception ex)
            {
                throw new DALException(cmd.CommandText, ex.InnerException);
            }
            finally
            {
                if (dr != null)
                    dr.Close();
            }
            return al;
        }

        #endregion

    }
}